using UnityEngine;
using System.Collections;

public class Parallax : MonoBehaviour 
{
    public float scrollSpeed = 0.5F;
    private CharMovement player;
    private float offset = 0;

	void Start () 
    {
        player = GameObject.FindWithTag("Player").GetComponent<CharMovement>();
	}

    void Update()
    {
        Vector3 charPosition = new Vector3(player.gameObject.transform.position.x + 2.5f, transform.position.y, transform.position.z);

        transform.position = charPosition;
        
        float newOffset = offset + player.GetSpeed()/player.speed * scrollSpeed;
        offset = newOffset;

        renderer.material.mainTextureOffset = new Vector2(offset, 0);
    }
}
